<?
	include_once(dirname(__FILE__).'/../../bootstrap/unit.php');
	include_once('bootstrap.php');

function hex2bin($h)
  {
  if (!is_string($h)) return null;
  $r='';
  for ($a=0; $a<strlen($h); $a+=2) { $r.=chr(hexdec($h{$a}.$h{($a+1)})); }
  return $r;
}
	
	//Pass data that would be sent from chibiPaint
	//.chi data
	$chi = hex2bin("43484942494f454b78daeddd499356d51d07e0ceca6df66ef201b2c947b04aa92cac2c9255c22a05edc8a0a0024ee080a8a00c223238a10c2a488182968a228228335a0a82a8383009e22c22c809bf93ba5d6d8a242436bcfd763f4fd55b763555d6e5e5de7bcef90fe7fcf1a20b2eece8e8f86d47f59b29a73ebfcf0f175ff0d73f779cf797f34ffd7cfe3fffac63707e7fea73dec57f1fd339e2777f280000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0d975e0c081b264c992f2d0430f958d1b37961f7ffcb1d59704401b78fffdf7cbc48913cbe5975f5eaeb9e69a3a8eecddbbb7d59705402ff7f3cf3f9723478e94975f7eb9dc78e38da5b3b3b34c9a34a97cf0c107adbe3400dac4e1c387cbecd9b3cb25975c526ebbedb6b263c78e565f12006de29b6fbe298f3df658b9ecb2cbcaa851a3cafcf9f3cb860d1bead872f2e4c9565f1e00bdd80f3ffc5073ea575d755519326448b9eebaebcab871e3ca030f3c50c792a3478fb6fa1201e8a54e9c38513ef9e493b27cf9f29a5f1f3e7c785d938c1c39b24c9d3a55ad16b4b9e43e1357d8b4695359b468518d5d270f0a3dedfbefbf2f6bd6ac29b7dc724bb9f4d24beb38327dfaf4b279f366e308f45219233217fce9a79f6adce0e0c18375ee97f162ca9429e5a69b6eaa7597893324de90dfc3d992d8d66bafbd56c68e1ddb55f3fbf0c30fd73e12e0dccb18f1f5d75fd77a97ac1f162c5850a64d9b56eeb8e38e72ebadb7767d12834e8d65335e641e78f5d557977beeb9a73cfbecb3e5a38f3eaa630d9c6d598fbcfaeaabe5faebafaf35bf93274f2e9f7df659ab2f0bfa8dd4b3a4dee5a5975e2ab7df7e7b193d7a74193162441d1b126bce73995acafc9cb9de95575e59c78e8c17894b7ff8e187755d02adf2f9e79f97193366d4fb347d231f7ffc71ab2f09fab4bcf377eedc59eb24b3a6c83a2263456aee130bc81a246b8963c78eb5fa52e1bffae28b2fbafa46264c9850ef5da06765dc488c6ace9c39751d917123eb8a7befbdb7bcf7de7badbe3cf8bf7df5d55775ef938c21c9b1a7a6c3fc077ebdd4a7bcf3ce3be5c1071fac752b596b2456f5fcf3cfd7bc07f4054defe115575c51e7473367ceacf7bd9c1c9cb9e4c30f1d3a54d6ad5b57e6cd9b57eebcf3ce9ad7c87a63cc9831e585175e28df7df75dab2f137a5ceab392574f5d60d3c33e77eedc9aabcb730194ba36cf1e732b56aca875f0c95d74af95bae1861b6a6d54e662798e52ef983cb97183fe206b913c1be95dcffd9fbac1279e78428d16fd569e89ad5bb7d6e7e0eebbefae73aba14387d698efa04183cae0c183bb6aa63276a43f63e5ca95b536dede41f44759873ff5d453356e9b5cdfcd37df5c9e79e699fa7be8cbb2decebb7ff5ead5357791bc60e2baa9a3cd9c2a6b8cc4a7b66fdf2e5708ffc1fefdfbcb238f3c526bd3f3193f7e7c8de326ef0e7d456aa4527ff8dc73cfd51ebef447a5af3be345eefbd427e6cf72c68e35059cb93c2fc983641fc63c4b59bba747f6e9a79fae73b0e44ea0dd2427913a91c58b17d71ea8d4463571a98c1db9dfdf7cf3cd1abf027e9dd46365bc481f6cf283d99b31cf5ce66659cf678fdf2fbffcb2d59709a7957950eecfdca78f3ffe789d035d7bedb55d71a9ac39f2fbdce3fabbe1ecc8b3b57bf7ee9a1f497d49c692ac4bf22ca606253d89a9e54aec4bed16ad94394feec3dc8fb92f73bfa6a6b6d91724f5534b972ead7b56bb57e1dcca9c2ecf677aa252ef9ef57fc6933ca3a905beefbefb6adcd89e3d9c0bb91fd39bb76ddbb61a5f4d2d54f2dd592ba70f23f767d6cfd92b24b5207219d07b24affefaebafd71c646a1933cfcb7ff30c27c69c1ac8f4b8e7ec76cf2e3d21f9b7ec2b95794a7216d95baad9abb639fba639434d1f06b4873cd76fbdf556dd1b2e7992ac4b860d1bd6752ee2fdf7df5ff713cd1e4072f09ca9ac63136f7ae59557eabd959ac0f4643467a5658d919c5ce252e9f5b3ee85f676fcf8f1b267cf9eda4372d75d77d571246b93d4b9646f87e43253279c334af6eddb67ef14ba242f91fda2530b953332d2c3977ba6192f322f495e63fefcf9e5edb7df3617813e2ee790646d927db7d2e3dee433136b48af62ce25c95863fed83f75efc7480e2db9b4dc1bcdbe20596f241ffec61b6fa8f9837e2c7990e43257ad5a55df15794fe41d91f965f226d9e73a634972f059c7d037654ef1affd1859a7e65e68f60579f1c517ebfa54ad14703addcfd969f226194b529fdffdcc4e63497b6bfa3172ae77fa2e72165ff77d4212a3caefdf7df7ddba173ac0ff226349f2eb194b12b3e8be2e498c2bf9776349fb68fa31b2d6cc794aa9a368fa31f249ff907e0ca0a73563c9a38f3e5ac79226ff9eb124b18d8c25c9d1cbbdf73ea9eb4eae2267cb24dfd5ec2d95f8546255e9c7387cf870ab2f13e807b2ef69f69938dd58927549f2ae39d3dd58d23af937dab56b5779f2c927ebbaa2e9e14b7e2be348fa31befdf6db565f26d08f25369e1879ea7fd35b927754c692cc73938f5fb3668df342cf91c49c0e1e3c58cf4cca9ab039472639ace4aed6af5fafbe16e89532e74d0d4fce74cf7e5c797725be9e7eb2c4b7f26ea3e7a5766acb962db59f2fb5b6e9e16bce1f4b3ec3f70eb493ac4b52db937eb3cc7ff34e4bbe36f194e4dce567cf4ceaa412074cfe29e3f3d1a347eb7891355dfa73962d5b56f73ecb9aaf59fba537c33eb640bbcbbb2f71f8193366d43124f5a19917e76cb9f42b7bc7fd52b3ef4c6adeb26eeb7ec677cee26b3ee9f94eee29df67f24fa9bfcd9e226285405f937974ce8f5bb87061ed33c83b2f31aec4e9d7ad5bd7af73b9598ba52f6fc58a1575bd96985fd61239db3be729251695ef2bebb88c17d99b30b5531987f37da656c17e98407f907ad29cc39b7aada62628f3ece9d3a7d79eb5f428ae5dbbb6c66012bbefabe75c67cc4c8c2f6bb17c17191ff27de4bb484dad738a014e2fb1fceccb97384dde9dcd1ec1997fa776283defd98f2bb199eca3929eb7458b16d5faa2cd9b37d77e939c6fda4eb994662fcb254b96d47d2bb33748c68cfc9d53c396b3c1dae9ef03d04a795f66ae9d7d5372565dce564cbea4d95323b19bc47012b7497e38bfcbde2a89df24279ffc71f6a3cf1eb0e93d499d6a72cbc9059c2eae93de878c594d5e219fee79869efe74ff7fe77a13b76bf6accc7ec8596b391b03a0e7257e95fc40cebe4a8e20f3f4f44d27e6d3d4aa765fbb24af9c3f4b8ef974eff38103079601030694418306d51cc3d9fc747676fee2937c46ae2f67797dfae9a7f216002dd2ac5d922b59b972655d832427dff441fcbb77faac59b3bcbb010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a067fceda23f5dd871ca3f003d807e08");

	
	//Create a psuedo-$_FILES
	$_FILES['picture']['name'] = 'test.png';
	$_FILES["picture"]['tmp_name'] = 'test.png';
	$_FILES["chibifile"]['tmp_name'] = 'test.chi';
	
	//Load applet plugin
	$a = new chibiPaintApplet();
	
	//Get the proper format for saving
	$data = $a->prepareDataForSave($params);
   	$t->cmp_ok($data["extension"][0], '==', 'png', 'Tests that the png extension has been properly parsed.');
	
	//Convert the returned data to hex to compare
   	$t->cmp_ok(bin2hex($data["data"][0]), '==', '89504e470d0a1a0a0000000d49484452000001900000012c080200000062d5729500000bf54944415478daedddeb5755f5bac0f1fdd7f54ff43245052fdc04e422200a8880a47809540ad248d3610a380c31d2f282d8c5e13d01b5201133300135e19c67ec39b635da7becb3cfc9230bf87c5e3476bc68af35d75cdff9fcd69a73aebffd17c03cf1379b00102c00c102040b40b000040b102c00c102102c40b000040b40b000c102102c00c102040b40b000040b102c00c102102c40b000040b40b000c102102c00c102040b40b000c102102c00c102040b40b000040b102c00c102102c40b000040b40b000c102102c00c102040b40b000040b102c00c102102c40b000040b40b000c102102c00c102040b40b000c102102c00c102040b40b000040b102c00c102102c40b000040b40b000c102102c00c102040b40b000040b102c00c102102c40b000040b40b000c102102c00c102040b40b000c102102c00c102040b40b000040b102c00c102102c40b000040b40b000c102102c00c102040b40b000040b102c00c10210acd7e7c18307478e1cd9bb77efa54b979e3d7b66838060a5aeefbfff7ecb962d2b56acc8cdcd8d6c0d0f0fdb262058296a6666e6f1e3c73d3d3dc5c5c54b972eadadad1d1818b05940b052daa3478f9a9a9ad2d2d22a2a2a6edcb861838060a5b4274f9eb4b6b62e5fbe3c3f3f7ffffefd7d7d7d51b1d9d9595b06042b154d4d4d1d397224333373e5ca95797979656565bb76ed8a724d4f4fdb38205829e7e5cb97f7efdfefe8e8d8b265cb9a356b62e0cac9c979f7dd777d8dc802333333136b88fefefe43870e353535f5f4f408d6fc36393979f6ecd9f2f2f265cb9645b61a1b1b2f5fbe2c5bccc736c591f8c58b17b156181d1d8da36f44aaa1a1a1a4a424373737d613b1aa88bf08d60259279e3973a6b4b43439fb61dfbe7d0f1e3cb05948d9364d4c4cdcb8712326a603070e6cdbb6adb2b272c33f94959515171727918ac3705656565d5dddf1e3c7878686a26882b5a0a6addededec2c2c2a54b976eddbaf5c71f7fb44d4829b3b3b34f9e3ce9eeeedeb871634141417676765469f9f2e5b1c7a6a5a5c5ff88236e464646d42a22d5d1d13138381833d75c3d5ac17a131e3e7cb873e7ce78f96b6b6befddbb6783900aa23bb76edd6a6d6d8d012ae6a628544545452c0562c88ad1e9f9f3e729f89805eb0df9f9e79f9333b6aaaaaa626fb04198db54c5eaafb9b939e6a64855cc50f5f5f5376fde4cfd472e586fcef8f8f8debd7ba359e5e5e5fdfdfda9790463617bf6ecd9d5ab57f7ecd9939393132355ac014f9c38313131315f1ebf60bd51c959a6e9e9e97164dbbd7b77ec3a6ff8334b16a1999999b1b1b173e7ce7df8e187d5d5d5d9d9d93155ad5bb7eee4c9934f9f3e9d5fcf45b0deb4a9a9a9dedede929292e4e4f80f3ef86070703076295b86bf2ec6f6818181cececec6c6c68a8a8a575ff3151515656565c59132f6bad2d2d2eeeeee79972ac19ae3512bf6aabcbcbcd8818a8b8bdbdbdb7d81c85fd99dbef9e69bd88b6a6a6ae228b86ad5aab4b4b477de7967c99225c9977d51ab86868653a74e3d78f0605e5f372658732906f583070fe6e4e4ac58b162fdfaf5c78e1d8bbfd82cfc870bbda8cf175f7cb167cf9ef2f2f2dcdcdc8c8c8c38fec530154bbfebd7af2fc80f49056beefdf4d34f2d2d2d2bff6ed3a64d274f9e1c1f1fb759f8975ebc78313434d4d5d5b56ddbb6c2c2c2cccccc8854ec39555555f1c7e1e1e1857de1bd60a584d8c906070777edda157b5eccf3959595870f1f8e83e4d4d4948d4378faf4e9d5ab573ff9e493dadada82828264d117b58a7de6c2850bb1245c24db41b052c8cb972f2352757575e9e9e96bd6ac89fd320e9b31def7f5f5fdf2cb2fb6cf223c8cc5eb1eaf7e5b5b5b1cc3d6ae5d9b2cfa62b08abfc4ae3287679c0b16bfcffc77eedc3978f060696969942b66aed853376cd8d0d4d4d4dbdb1beb475f292ef8e356bccaf15ac72b1efb4076767672714c4545c5d1a347efdfbfbf987700c14ae9036cecb8274e9ca8aeae8e2540c42bf6dd929292eddbb7777575cded255dbcf6d77a6262e2db6fbf3d7cf8704343435151518cd8cb962d8bd73d26ee9e9e9eb1b131778514ac79637c7cfcabafbedab66d5b5656561c6fe39fb14fd7d6d6b6b7b7f7f7f73f7efcd8de3c1f4d4d4dddba752b0e3fbb76ed2a2b2b4b6e8790dc4c2db907e43c3d5b4ab0f87d17ffeebbeff6eddb5750501033d7ead5ab937b9ceed8b1a3a3a3e3e6cd9b3ea74ffd257f2ceb4e9f3e1d2fe2a64d9bf2f3f3933b3ec630555555158bbe818101b3b3602d34bffdf6dbddbb778f1d3bb679f3e6c8568c5d999999ebd6adabacac6c69693973e6ccc8c888eb7e52c4ccccccc3870f2f5cb870e0c0819a9a9a78999248c521a7b4b474fffefd57ae5c71a411acc562727232c6aed6d6d6e2e2e2e403da5853ac5fbf7eebd6ad513447ec391ca69273a6b66fdf5e5252122f4a72714c4c554d4d4de7cf9ff7e5af602d6ab3b3b36363639f7ffe79bc43e2ed11ef8d3892171515d5d7d747b9060707632eb395dec0f1e38fe74cc5fc1b2f447271cc679f7d1693afef79058b7f71784f6ecf967cda15e52a2c2c7c75675be57aed878a18972e5dbad4d6d6b671e3c65717cac4ea2ffe72edda3537f5172cfed372ddbc7933ca152b91573357ac163b3a3a94eb2f4ace998a91b6b9b9b9acac2c39672a6cd8b0c1395382c56b28d7fbefbf1fe54a3ea48f72c53a25ca75f7ee5d9fd0ffaf8c8f8f9f3f7f7ef7eeddc5c5c5c9057db1f48b35604f4fcfa3478f6c1fc1e2b579fefcf9f5ebd7ff54ae98b9bababaeeddbba75cff7ed3ddbe7dfbe38f3f8e192a39b733272727b2d5d7d7f7ebafbfda3e82c5ffa367cf9e5dbb76ada5a5252f2f2fde7b51ae9817b66fdf7ef6ecd97974dbdc37205676a3a3a3dddddd31902677314b4f4fafababbb78f1a2d311048b39181cae5ebdba77efdeb56bd7c6bb313b3bbbaaaa2a968af12e5de45b667272f2ebafbfdeb76f5f4949c9aa55ab921b2e1e3d7ad496112c5262e6ba74e9524d4d4d4c10f1fe2c2b2b8be5cfd0d0d0c2fef078767636f989e308f7f4f474442a06cc8181814f3ffdb4baba3a06cf64fc6c6a6a5a9cf748102c525abc7b6fdfbebd73e7ce6856464646cc147bf6ecb972e5ca427aaf261739b5b6b6c62cf9eaf6e7e5ff505a5a9a9f9f1fcf7dc58a151b376e3c7dfab435b26091ea73c7f0f0f0471f7d949b9b1befdb582d3634349c3b776e5e7fba1ca3e2c8c8486767674c91c9efc72c59b2e4d54f1cc75c19915ab972e5ead5ab23d3f1dcefddbbe7c272c1623e191f1f3f79f264515151f2a558cc238d8d8d6d6d6dc78f1ffff2cb2f6395343a3a9afa77108fcec66a3746c5782211a6782ef1447a7a7adc905ab05880a6a7a72f5cb8100ba8f4bf8b19242694bcbcbcc2c2c2f5ebd7c7baa9bebebeb9b9f9d0a143dddddd972f5fbe7bf7ee93274fe6fcc3afe42af123478e54565666656545a7e261b7b4b4dcb973c7599d82c502176ff218496eddbad5dbdb7bf0e0c19d3b772657a2c47a2af93584ccccccf8d78282825852959595555757efd8b163fffefd5d5d5d172f5e1c1818989898f8d322abafaf2f3af8ea47f4fef8837aff67affe23f11862319b5c13be79f3e61809dd644ab058ec6249383232d2dfdfdfd9d919f34b6d6d6dacbc92f3005e8d63f9f9f9f1c7d2d2d23fc5e5edb7df7eebadb792dfd17b2d96fe415a5a5afcffb6b7b7fff0c30f3e8d122cf81fc6b1ebd7af9f3a752a86ac868686e46ca67feecb7befbda72608162058008205205880600108168060018205205800820508168060018205205800820508168060010816205800820520588060010816806001820520580082050816806001081620580082052058806001081680600182052058008205081680600182052058008205081680600108162058008205205880600108168060018205205800820508168060010816205800820520588060010816806001820520580082050816806001820520580082050816806001081620580082052058806001081680600182052058008205081680600108162058008205205880600108168060018205205800820508168060018205205800820508168060010816205800820520588060010816806001820520580082050816806001081620580082052058806001081680600182052058008205081680600182052058008205081680600108162058008205205880600108168060018205205800820508168060010816205800820520588060010816c0effe1bcaff6fd7906f5cb70000000049454e44ae426082', 'Tests that the png data has been properly stored in the array.');
	
	
?>